import java.util.Comparator;
import java.util.PriorityQueue;

public class Test1   {
    public static void main(String[] args) {
        PriorityQueue<A> priorityQueue = new PriorityQueue<>(new aCmp());
        priorityQueue.offer(new A(1));
        priorityQueue.offer(new A(2));
        priorityQueue.offer(new A(3));
        System.out.println(priorityQueue.poll());
    }
}
class aCmp implements Comparator<A>{

    @Override
    public int compare(A o1, A o2) {
        return o1.age-o2.age;
    }
}

class A {
    public A(int age) {
        this.age = age;
    }

    int age ;

    @Override
    public String toString() {
        return "A{" +
                "age=" + age +
                '}';
    }
}